package bpm.dao.impl.process;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;

import org.springframework.jdbc.core.RowMapper;

import bpm.domain.process.Category;
import bpm.domain.process.ProcessDefinition;

/**
 * 
 * @author <a mailto="hwangsyin@gmail.com">King</a>
 *
 */
public class ProcessDefinitionMapper implements RowMapper {
	private boolean lazy = true;
	
	public ProcessDefinitionMapper() {}
	public ProcessDefinitionMapper(boolean lazy) {
		this.lazy = lazy;
	}

	public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
		ProcessDefinition pd = new ProcessDefinition();
		
		pd.setId(rs.getString("id"));
		pd.setName(rs.getString("name"));
		pd.setCategory(new Category(rs.getString("category_id"), rs.getString("category_name")));
		pd.setEnableString(rs.getString("enable"));
		pd.setCreateTime(new Date(rs.getDate("create_time").getTime()));
		pd.setLastUpdateTime(new Date(rs.getDate("last_update_time").getTime()));
		pd.setDescription(rs.getString("description"));
		pd.setDeployed(true);
		
		if(!lazy) {
			pd.setDiagram(rs.getBytes("diagram"));
		}
		
		return pd;
	}

}
